﻿@using GraduationProject.Model
@{
    Layout = null;
    var SortModel = ViewData["SortModel"] as List<SortList>;
    var NovelModel = ViewData["NovelModel"] as Novel;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>文章列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="~/Content/layui/css/layui.css" rel="stylesheet" />
    <link href="~/Content/css/public.css" rel="stylesheet" />
</head>
<body class="childrenBody">
    <form class="layui-form layui-row layui-col-space10">
        <div class="layui-col-md9 layui-col-xs12">
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md9 layui-col-xs7">
                    <div class="layui-form-item magt3">
                        <label class="layui-form-label">文章标题</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input newsName" name="NovelTitle" value="@NovelModel.NovelTitle" lay-verify="newsName" placeholder="请输入文章标题">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容摘要</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入内容摘要" name="NovelSummary" value="" class="layui-textarea abstract">@NovelModel.NovelSummary</textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md3 layui-col-xs5">

                </div>
            </div>
            <div class="layui-form-item magb0">
                <label class="layui-form-label">文章内容</label>
                <div class="layui-input-block">
                    <textarea class="layui-textarea layui-hide" name="content" id="news_content" value="">@Html.Raw(HttpUtility.HtmlDecode(NovelModel.NovelBody))</textarea>
                </div>
            </div>
        </div>
        <div class="layui-col-md3 layui-col-xs12">
            <blockquote class="layui-elem-quote title"><i class="seraph icon-caidan"></i> 分类目录</blockquote>
            <div class="border category">
                <div class="">
                    <select lay-verify="required" name="SortType" id="SortType" lay-filter="column">
                        @if (SortModel != null)
                        {
                            foreach (var item in SortModel)
                            {
                                <option value="@item.SortID">@item.SortName</option>
                            }
                        }
                    </select>
                </div>
            </div>
            <blockquote class="layui-elem-quote title magt10"><i class="layui-icon">&#xe609;</i> 发布</blockquote>
            <div class="border">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon">&#xe609;</i> 发　布</label>
                    <div class="layui-input-block">
                        <input type="radio" name="release" title="立即发布" lay-skin="primary" lay-filter="release" checked />
                        <input type="radio" name="release" title="定时发布" lay-skin="primary" lay-filter="release" />
                    </div>
                </div>
                <div class="layui-form-item layui-hide releaseDate">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" id="release" placeholder="请选择日期和时间" readonly />
                    </div>
                </div>
                <div class="layui-form-item openness">
                    <label class="layui-form-label"><i class="seraph icon-look"></i> 评论</label>
                    <div class="layui-input-block">
                        @if (NovelModel.IsBan)
                        {
                            <input type="radio" name="openness" value="true" title="开放评论" lay-skin="primary" checked />
                            <input type="radio" name="openness" value="false" title="静止评论" lay-skin="primary" />
                        }
                        else
                        {
                            <input type="radio" name="openness" value="true" title="开放评论" lay-skin="primary" />
                            <input type="radio" name="openness" value="false" title="静止评论" lay-skin="primary" checked />
                        }
                    </div>
                </div>
                <input type="hidden" value="@NovelModel.CreateTime" id="CreateTime" name="CreateTime">
                <input type="hidden" value="@NovelModel.CreateUser" id="CreateUser" name="CreateUser">
                <input type="hidden" value="@NovelModel.IsAdminBan" id="IsAdminBan" name="IsAdminBan">
                <input type="hidden" value="@NovelModel.AgreeNum" id="AgreeNum" name="AgreeNum">
                <input type="hidden" value="@NovelModel.DisagreeNum" id="DisagreeNum" name="DisagreeNum">
                <input type="hidden" value="@NovelModel.ClickNum" id="ClickNum" name="ClickNum">
                <div class="layui-form-item newsTop">
                    <label class="layui-form-label"><i class="seraph icon-zhiding"></i> 置　顶</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="newsTop" id="newsTop" lay-skin="switch" lay-text="是|否" @(NovelModel.IsTop == true ? "checked" : "unchecked")>
                    </div>
                </div>
                <hr class="layui-bg-gray" />
                <div class="layui-right">
                    <button class="layui-btn" lay-submit lay-filter="addNews">修改</button>
                </div>
            </div>
        </div>
    </form>
    <script src="~/Content/layui/layui.js"></script>
    <script>
        layui.use(['form', 'layer', 'layedit', 'laydate', 'upload'], function () {
            var form = layui.form
            layer = parent.layer === undefined ? layui.layer : top.layer,
                laypage = layui.laypage,
                upload = layui.upload,
                layedit = layui.layedit,
                laydate = layui.laydate,
                $ = layui.jquery;

            //用于同步编辑器内容到textarea
            layedit.sync(editIndex);



            //格式化时间
            function filterTime(val) {
                if (val < 10) {
                    return "0" + val;
                } else {
                    return val;
                }
            }
          

            form.verify({
                newsName: function (val) {
                    if (val == '') {
                        return "文章标题不能为空";
                    }
                },
                content: function (val) {
                    if (val == '') {
                        return "文章内容不能为空";
                    }
                }
            })
            form.on("submit(addNews)", function (data) {
                //截取文章内容中的一部分文字放入文章摘要
                var abstract = layedit.getText(editIndex).substring(0, 50);
                //弹出loading
                var index = top.layer.msg('数据提交中，请稍候', { icon: 16, time: false, shade: 0.8 });

                var params = {
                    NovelTitle: $(".newsName").val(),  //文章标题
                    NovelSummary: $(".abstract").val(),  //文章摘要
                    NovelBody: layedit.getContent(editIndex).split('<audio controls="controls" style="display: none;"></audio>')[0],  //文章内容
                    IsBan: $('.release').val() == 0 ? true : false,
                    IsTop: $('#newsTop').val() == "on" ? true : false,    //是否置顶
                    SortType: data.field.SortType,
                    CreateTime: $("#CreateTime").val(),
                    CreateUser: $("#CreateUser").val(),
                    IsAdminBan: $("#IsAdminBan").val(),
                    AgreeNum: $("#AgreeNum").val(),
                    DisagreeNum: $("#DisagreeNum").val(),
                    ClickNum: $("#ClickNum").val()
                };
                $.ajax({
                    type: "post",
                    url: "/Admin/AdminNovel/AdminInsert",
                    data: params,
                    dataType: "json",
                    success: function (res) {
                        if (res.code == 0) {
                            layer.msg(res.msg, { icon: 1 });
                            window.parent.location.reload();
                        }
                        else {
                            layer.msg(res.msg, { icon: 2 });
                        }
                    }
                });
              
                return false;
            })

            //预览
            form.on("submit(look)", function () {
                //--------班组配置---------
                window.location.replace('/Admin/AdminComment/Index?NovelID=' + + '');
                return false;
            })
            layedit.set({
                uploadImage: {
                    url: '/Admin/AdminNovel/AdminUploadImage' //接口url
                    , type: 'post' //默认post
                }
            });
            //创建一个编辑器
            var editIndex = layedit.build('news_content', {
                height: 535
            });

        })
    </script>
</body>
</html>
